package com.fgr.service.Impl;

import com.fgr.beans.Donation;
import com.fgr.mapper.DonationMapper;
import com.fgr.service.DonationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DonationServiceImpl implements DonationService {
    @Autowired
    DonationMapper donationMapper;

    @Override
    public String insertDonation(Donation donation) {
        Integer integer = donationMapper.insertDonation(donation);
        if (integer>0){
            return "SUCCESS";
        }else {
            return "ERRO";
        }
    }

    @Override
    public List<Donation> selectAllDonation(Integer publish) {
        List<Donation> donations = donationMapper.selectAllDonation(publish);
        return donations;
    }

    @Override
    public Donation selectDonationByDnId(Integer dnId) {
        Donation donation = donationMapper.selectDonationByDnId(dnId);
        return donation;
    }

    @Override
    public String deleteDonationByDnId(Integer dnId) {
        Integer integer = donationMapper.deleteDonationByDnId(dnId);
        if (integer>0){
            return "SUCCESS";
        }else {
            return "ERRO";
        }
    }

    @Override
    public Donation selectDonationAndUserAndType(Integer dnId) {
        Donation donation = donationMapper.selectDonationAndUserAndType(dnId);
        return donation;
    }

    @Override
    public String updateDonationPublishByDnId(Integer dnId) {
        Integer integer = donationMapper.updateDonationPublishByDnId(dnId);
        if (integer>0){
            return "SUCCESS";
        }else {
            return "ERRO";
        }    }

    @Override
    public String updateDonation(Donation donation) {
        Integer integer = donationMapper.updateDonation(donation);
        if (integer>0){
            return "SUCCESS";
        }else {
            return "ERRO";
        }
    }
}
